use crate::algorithms::eval_static::encode::*;
use crate::sketchbook::properties::static_props::StatPropertyType;
use crate::sketchbook::Sketch;
use biodivine_lib_param_bn::BooleanNetwork;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProcessedStatProp {
pub id: String,
pub formula: String,
}
impl ProcessedStatProp {
pub fn mk_fol(id: &str, formula: &str) -> ProcessedStatProp {
ProcessedStatProp {
id: id.to_string(),
formula: formula.to_string(),
}
}
pub fn id(&self) -> &str {
&self.id
}
}
pub fn process_static_props(
sketch: &Sketch,
bn: &BooleanNetwork,
) -> Result<Vec<ProcessedStatProp>, String> {
let mut static_props = sketch.properties.stat_props().collect::<Vec<_>>();
static_props.sort_by(|(a_id, _), (b_id, _)| a_id.cmp(b_id));
let mut processed_props = Vec::new();
for (id, stat_prop) in static_props {
let stat_prop_processed = match stat_prop.get_prop_data() {
StatPropertyType::GenericStatProp(prop) => {
ProcessedStatProp::mk_fol(id.as_str(), prop.processed_formula.as_str())
}
StatPropertyType::RegulationEssential(prop)
| StatPropertyType::RegulationEssentialContext(prop) => {
let input_name = prop.input.clone().unwrap();
let target_name = prop.target.clone().unwrap();
let mut formula = encode_regulation_essentiality(
input_name.as_str(),
target_name.as_str(),
prop.clone().value,
bn,
);
if let Some(context_formula) = &prop.context {
formula = encode_property_in_context(context_formula, &formula);
}
ProcessedStatProp::mk_fol(id.as_str(), &formula)
}
StatPropertyType::RegulationMonotonic(prop)
| StatPropertyType::RegulationMonotonicContext(prop) => {
let input_name = prop.input.clone().unwrap();
let target_name = prop.target.clone().unwrap();
let mut formula = encode_regulation_monotonicity(
input_name.as_str(),
target_name.as_str(),
prop.clone().value,
bn,
);
if let Some(context_formula) = &prop.context {
formula = encode_property_in_context(context_formula, &formula);
}
ProcessedStatProp::mk_fol(id.as_str(), &formula)
}
StatPropertyType::FnInputEssential(prop)
| StatPropertyType::FnInputEssentialContext(prop) => {
let fn_id = prop.target.clone().unwrap();
let input_idx = prop.input_index.unwrap();
let number_inputs = sketch.model.get_uninterpreted_fn_arity(&fn_id)?;
let mut formula = encode_essentiality(
number_inputs,
input_idx,
fn_id.as_str(),
prop.clone().value,
);
if let Some(context_formula) = &prop.context {
formula = encode_property_in_context(context_formula, &formula);
}
ProcessedStatProp::mk_fol(id.as_str(), &formula)
}
StatPropertyType::FnInputMonotonic(prop)
| StatPropertyType::FnInputMonotonicContext(prop) => {
let fn_id = prop.target.clone().unwrap();
let input_idx = prop.input_index.unwrap();
let number_inputs = sketch.model.get_uninterpreted_fn_arity(&fn_id)?;
let mut formula = encode_monotonicity(
number_inputs,
input_idx,
fn_id.as_str(),
prop.clone().value,
);
if let Some(context_formula) = &prop.context {
formula = encode_property_in_context(context_formula, &formula);
}
ProcessedStatProp::mk_fol(id.as_str(), &formula)
}
};
processed_props.push(stat_prop_processed)
}
Ok(processed_props)
}